package com.zj.leetcode.medium;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: algorithm
 * @description:
 * 最长回文子串
 * 5 longest-palindromic-substring
 * @author: Zhang Bo
 * @create: 2022-07-15 17:53:09
 **/
public class LongestPalindromicSubstring{
    public static void main(String[] args) {
        Solution solution = new LongestPalindromicSubstring().new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(list.isEmpty());
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        // 最长回文子串
        public String longestPalindrome(String s) {
            int n = s.length(), res = 0;
            int p1 = 0, p2 = 0;

            // 一个中心点
            for(int i=0; i<n; i++){
                int left = i, right = i;
                while(left >= 0 && right < n){
                    if(s.charAt(left) == s.charAt(right)){
                        if(right - left + 1 > res){
                            res = right - left + 1;
                            p1 = left; p2 = right;
                        }
                        left--; right++;
                    }else break;
                }
            }

            // 两个中心点
            for(int i=0; i<n-1; i++){
                int left = i, right = i+1;
                while(left >= 0 && right < n){
                    if(s.charAt(left) == s.charAt(right)){
                        if(right - left + 1 > res){
                            res = right - left + 1;
                            p1 = left; p2 = right;
                        }
                        left--; right++;
                    }else break;
                }
            }
            return s.substring(p1, p2+1);
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
